package com.hyst.web;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PatchMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.hyst.common.ResultBean;
import com.hyst.common.ResultPage;
import com.hyst.domain.Student;
import com.hyst.domain.StudentView;
import com.hyst.service.TryListenService;



/**
 * 试听管理
 * @author knight
 *
 */
@RestController
@RequestMapping("studentview")
@CrossOrigin(maxAge = 3600, origins = "*")
public class TryListenController {
	@Autowired
	private TryListenService tryListenService;
	
	@GetMapping
	public ResultPage<StudentView> getTryListen(StudentView student) {
		return ResultPage.success(tryListenService.listview(student));
	}

	@PostMapping
	public ResultBean<Student> creat(final Student student) {
		return ResultBean.success(tryListenService.insert(student));
	}

	/**
	 * @Description: 根据主键查询
	 * @param studentId
	 * @return ResultBean<Student>
	 */
	@GetMapping("{studentId}")
	public ResultBean<Student> getByPriKey(@PathVariable("studentId") final String studentId) {
		return ResultBean.success(tryListenService.getByPriKey(studentId));
	}

	/**
	 * @Description: 根据主键更新全字段
	 * @param student
	 * @return ResultBean<Student>
	 */
	@PatchMapping("{studentId}")
	public ResultBean<Student> update(final Student student) {
		return ResultBean.success(tryListenService.update(student));
	}

	/**
	 * @Description: 根据主键更新不为默认值的字段
	 * @param student
	 * @return ResultBean<Student>
	 */
	//@PutMapping("{studentId}")
	@PostMapping("{studentId}")
	public ResultBean<Student> updatePatch(@PathVariable("studentId") final String studentId,
			final Student student) {
		return ResultBean.success(tryListenService.updateSelective(student));
	}

	/**
	 * @Description: 根据主键删除
	 * @param studentId
	 * @return ResultBean<Student>
	 */
	@DeleteMapping("{studentId}")
	public ResultBean<Student> delete(@PathVariable("studentId") final String studentId) {
		return ResultBean.success(tryListenService.delete(studentId));
	}
}
